package com.patterns.demo.observer.first.subject;

import com.patterns.demo.observer.first.observer.Observer;

import java.util.Enumeration;
import java.util.Vector;

/**
 * Author: SamGroves
 * <p>
 * Description:
 * <p>
 * Date: 2017/12/19
 */
public abstract class AbstractSubject implements Subject {

    private Vector<Observer> vector = new Vector<>();

    @Override
    public void add(Observer observer) {
        vector.add(observer);
    }

    @Override
    public void del(Observer observer) {
        vector.remove(observer);
    }

    @Override
    public void notifyObserver() {
        Enumeration<Observer> enumeration = vector.elements();

        while (enumeration.hasMoreElements()) {
            enumeration.nextElement().update();
        }
    }
}
